﻿using STHPMS1.DAL.D_Core;
using System.Data;
using ServiceStack.OrmLite;
using STHPMS1.ICore.I_Entity.Stmpms1;
using STHPMS1.Common.C_Entity.Stmpms1;
using STHPMS1.ICore.I_DAL.Repository;
using System.Collections.Generic;
namespace STHPMS1.DAL.D_Repository
{
    public class Dp_Proj_RecomRepository : DalBase, IDp_Proj_RecomRepository
    {
        /// <summary>
        /// 更新终选措施 设置为1
        /// </summary>
        /// <param name="rdwayid"></param>
        /// <param name="mainsegid"></param>
        /// <param name="values"></param>
        public void SetPREVEN_MEASURE(string anniname, string analy_year, string mainsegid, int values)
        {
            IDbConnection conn = Adapter.OpenDbConnection();
            string strsql = "update DP_PREVEN_DETAIL set PREVEN_MEASURE=" + values + " where ID in(select top 1 id from DP_PREVEN_DETAIL where ANNI_NAME='" + anniname + "' AND ANALY_YEAR='" + analy_year + "' and  [MAINSEGID]='" + mainsegid + "' and SECON_MEASURE=1 order by JUDGE_COEF desc)";
            conn.ExecuteNonQuery(strsql);
        }

        /// <summary>
        /// 计算综合评判系数（权重和分值相乘）
        /// </summary>
        /// <param name="rdclass"></param>
        /// <param name="colums"></param>
        /// <returns></returns>
        public double GetJUDGE_COEF(int rdclass, string colums)
        {
            IDbConnection conn = Adapter.OpenDbConnection();
            string strsql = "select (sum(DP_INFECT_COE.WEIGHT_COE *DP_INFECT_VALUE." + colums + "))/100 from DP_INFECT_COE left join DP_INFECT_VALUE on DP_INFECT_COE.INFECT_FACTOR=DP_INFECT_VALUE.INFECT_FACTOR where DP_INFECT_COE.RD_CLASS like '%" + rdclass + "%'";
            return conn.Scalar<double>(strsql);
        }
    }
}
